import CryptoJS from './aes'

//解密方法
export function Decrypt(word, jmDataKey) {
    var key = CryptoJS.enc.Utf8.parse(jmDataKey)
    var iv = CryptoJS.enc.Utf8.parse(jmDataKey)
    var encryptedHexStr = CryptoJS.enc.Hex.parse(word)
    var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
    var decrypt = CryptoJS.AES.decrypt(srcs, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    })
    var decryptedStr = (decrypt.toString(CryptoJS.enc.Utf8)).toString()
    return decryptedStr
}
//加密方法
export function Encrypt(word, jmDataKey) {
    var key = CryptoJS.enc.Utf8.parse(jmDataKey)
    var iv = CryptoJS.enc.Utf8.parse(jmDataKey)
    var srcs = CryptoJS.enc.Utf8.parse(word)
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    })
    return encrypted.ciphertext.toString().toUpperCase()
}